/*
 * ShopInfoImageProvider.java
 * business
 *
 * Created by ChenTao on 2017/3/2.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.recyclerview.provider;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.yidiandao.business.R;
import com.yidiandao.business.manager.ImageManager;
import com.yidiandao.business.ui.picturescan.PictureScanActivity;
import com.yidiandao.business.utils.ImageLoader;

import me.drakeet.multitype.ItemViewProvider;

/**
 * 店铺详情，图片 Provider
 *
 * <p>Created by ChenTao(chentao7v@gmail.com) on 2017/3/2 14:42
 */
public class ShopInfoImageProvider
        extends ItemViewProvider<String, ShopInfoImageProvider.ViewHolder> {

    private Activity mActivity;

    public ShopInfoImageProvider(Activity activity) {
        mActivity = activity;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View rootView = inflater.inflate(R.layout.item_shop_info_image, parent, false);
        return new ViewHolder(rootView);
    }

    @Override
    protected void onBindViewHolder(@NonNull final ViewHolder holder, @NonNull String data) {
        ImageLoader.loadImage(mActivity, holder.ivImage, data);
        holder.ivImage.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ImageManager.getInstance()
                                .setFinalImageList(
                                        ImageManager.getInstance().getCurrentImageList());
                        PictureScanActivity.actionStart(mActivity, getPosition(holder), false);
                    }
                });
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView ivImage;

        private ViewHolder(View itemView) {
            super(itemView);

            ivImage = (ImageView) itemView.findViewById(R.id.iv_shop_info_image);
        }
    }
}
